package service.impl.v2;

import java.text.DecimalFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.v2.BoardVOMapper;
import dao.v2.MessageVOMapper;
import model.BoardVO;
import model.LogEarnVO;
import model.MemberMsgVO;
import model.OrderVO;
import model.SysMsgVO;
import model.UorderVO;
import service.v2.MessageService;
@Service
public class MessageServiceImpl implements MessageService{

	@Autowired
	private MessageVOMapper dao;
	
	public void getTest() {
		// TODO Auto-generated method stub
		dao.getTest();
	}
	
	//我的资产 未读消息冒泡
	public int selectMyAssetsReadN(String member_id) {
		return dao.selectMyAssetsReadN(member_id);
	}
	public String getSendOrder(String member_id) {
		// TODO Auto-generated method stub
		return dao.getSendOrder(member_id);
	}
	public String getSendOrderReadN(String member_id) {
		// TODO Auto-generated method stub
		return dao.getSendOrderReadN(member_id);
	}
	public List<UorderVO> getDeliverAssist(String member_id) {
		// TODO Auto-generated method stub
		//重置物流助手数字
		dao.resetMemberMsg(member_id, "3");
		return dao.getDeliverAssist(member_id);
	}
	
	public int getUnReadNum(String cat, String member_id) {
		return dao.getUnReadNum( cat,member_id);
	}
	public String getLastNoticeTitle(String loadPropertie) {
		return dao.getLastNoticeTitle(loadPropertie);
	}
	// 我的资产>显示最新一笔收入
	public LogEarnVO selectLatestIncome(String member_id, LogEarnVO logEarnVO) {
		LogEarnVO vo = dao.selectLatestIncome(member_id,logEarnVO);
		if(vo !=null){
			vo.setEarn_money(vo.getFree_cash());
			double num_i = 0; 
			DecimalFormat df = new DecimalFormat("######0.00");
			if("2".equals(vo.getType())){
				if("2".equals(vo.getAward())){
					vo.setEarn_money(vo.getEarn());
				}
				if("3".equals(vo.getAward())){
					num_i=Double.valueOf(vo.getFree_cash()).doubleValue()+Double.valueOf(vo.getBuy_cash()).doubleValue();
					vo.setEarn_money(df.format(num_i)+"");
				}
				if("4".equals(vo.getAward())){
					num_i=Double.valueOf(vo.getFree_cash()).doubleValue()+Double.valueOf(vo.getBuy_cash()).doubleValue();
					vo.setEarn_money(df.format(num_i)+"");
				}
			}
		}
		return vo;
	}

	public void saveErrorMsg(String error_msg, String error_url, String member_id) {
		// TODO Auto-generated method stub
		dao.saveErrorMsg(error_msg, error_url, member_id);
	}

	public List<UorderVO> getCancelOrder(OrderVO order) {
		return dao.getCancelOrder(order);
	}

	public int getCancelOrderToTal(OrderVO order) {
		// TODO Auto-generated method stub
		return dao.getCancelOrderToTal(order);
	}

	public int getSysMsgTotal(SysMsgVO sys) {
		// TODO Auto-generated method stub
		return dao.getSysMsgTotal(sys);
	}
	
	
	
	public MemberMsgVO getMemberMsg(String member_id) {
		// TODO Auto-generated method stub
		return dao.getMemberMsg(member_id);
	}

	/*
	 	notice_num    1
		sys_num         2
		ems_num       3
		cash_num      4
		praise_num    5
	 */
	
	public void updMemberMsg(String member_id, String upd_num) {
		// TODO Auto-generated method stub
		dao.updMemberMsg(member_id, upd_num);
	}
	
	/*
		notice_num    1
		sys_num         2
		ems_num       3
		cash_num      4
		praise_num    5
	 */
	
	public void resetMemberMsg(String member_id, String upd_num) {
		// TODO Auto-generated method stub
		dao.resetMemberMsg(member_id, upd_num);
	}

	public String getLastCancelOrder(String member_id) {
		// TODO Auto-generated method stub
		return dao.getLastCancelOrder(member_id);
	}

	public List<SysMsgVO> SysMsg(SysMsgVO sys) {
		return dao.SysMsg(sys);
	}

	public String getLastSysMsg(String member_id) {
		return dao.getLastSysMsg(member_id);
	}
	
	@Override
	public void insertLimitedMsg(String limited_id, String tel, String member_id) {
		dao.insertLimitedMsg(limited_id, tel, member_id);
	}
	
	@Override
	public int checkLimitedMsg(String limited_id, String member_id) {
		return dao.checkLimitedMsg(limited_id, member_id);
	}
	
	@Override
	public void updateLimitedMsg(String limited_id, String tel, String member_id) {
		dao.updateLimitedMsg(limited_id, tel, member_id);
	}
}
